package router

import "github.com/gin-gonic/gin"

type IRouter interface {
	Register(group *gin.RouterGroup)
}

type registerHelper struct {
	routerGroup *gin.RouterGroup
	rModule []IRouter
}

func (rh *registerHelper)Init(rg *gin.RouterGroup,routers ...IRouter) *registerHelper {
	if len(routers)>0{
		for _,v := range routers {
			rh.rModule = append(rh.rModule,v)
		}
	}
	rh.routerGroup = rg
	return rh
}

//add a router module
func (rh *registerHelper) Add(routers ...IRouter) *registerHelper {
	if len(routers)>0{
		for _,v := range routers {
			rh.rModule = append(rh.rModule,v)
		}
	}
	return rh
}

func (rh *registerHelper)RunRegister()  {
	for _,r := range rh.rModule {
		r.Register(rh.routerGroup)
	}
}

func NewRegisterHelper() *registerHelper {
	routers := make([]IRouter,0,0)
	return &registerHelper{rModule:routers}
}